<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>wenjuandiaocha</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="/js/vue.js"></script>
    <!-- 引入样式element-->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
            font-size: 14px;
            /* 可以消除边框对长宽的影响 */
        }

        #container {
            position: fixed;
            top: 0;
            right: 0;
            left: 0;
            bottom: 0;
            background: url("/img/bacg.jpg") no-repeat center center;
        }

        .forms {
            width: 600px;
            margin: 150px auto;
            border: 1px solid rgba(0, 0, 0, 0.2);
            padding: 20px;
            border-radius: 10px;
            box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
            background-color: #fff;
        }
        .forms .logo{
            width:100%;
            height:100px;    
        }
        .forms .logo img{
            height:60%;
        }
        .forms .logo span{
            line-height:60px;
            font-size:25px;
            float:right;
            margin-right:40%;
        }
       .forms form div button{
            margin-left: 100px;
            margin-right:30px;
        }
        a {
            color: rgba(0, 0, 0, 0.5);
            text-decoration: none;
        }

        a:hover {
            color: rgba(0, 0, 0, 0.8);
        }
    </style>
</head>

<body>
    <div id="container">
        <div class="forms">
            <div class="logo">
                <img src="/img/logo.png" alt="">
                <span>
                    用户登陆
                </span>
            </div>
            <el-form id="loginFrm" :status-icon="true" :rules="rules" label-position="left" action="/login" method="post" ref="form"
                :model="form" label-width="80px">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="form.username" name="username"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input type="password" v-model="form.password" name="password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button @click="login()" type="primary">登陆</el-button>
                    <el-button type="primary" plain><a href="/regist">立即注册</a></el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
    <script>
        new Vue({
            el: '#container',
            methods: {
                login: function () {
                    //验证用户名是否已经存在
                    this.$refs.form.validate(function (valid) {
                        if (valid) {
                            loginFrm.submit()
                        }
                    })
                }
            },
            data: function () {
                return {
                    form: {
                        username: '',
                        password: '',
                    },
                    rules: {
                        username: [
                            {
                                validator: function (rule, value, callback) {
                                    var usernamereg = /^[a-z]\w{2,17}$/
                                    if (value.trim() == '') {
                                        callback(new Error('请输入用户名'))
                                    } else {
                                        callback()
                                    }
                                }
                            },
                        ],
                        password: [
                            {
                                validator: function (rule, value, callback) {
                                    var len = value.length
                                    if (value.trim() == '') {
                                        callback(new Error('请输入密码'))
                                    } else {
                                        callback()
                                    }
                                }
                            }
                        ]

                    }
                }
            },
        })
    </script>
</body>

</html>